package interview.huawei.myself.machine_test;

import java.util.Scanner;

public class Main3 {
    private static int count = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
//        1 4 3 4 5
//        r y b b r
        String digits_str = in.nextLine();
        String colors_str = in.nextLine();
        String[] digitsArray = digits_str.split(" ");
        int[] digits = new int[digitsArray.length];
        for (int i = 0; i < digitsArray.length; i++) {
            digits[i] = Integer.parseInt(digitsArray[i]);
        }
        String[] colors = colors_str.split(" ");
        getCountOfPoker(digits, colors, new boolean[digits.length], 0, -1);
        System.out.println(count);
    }

    private static void getCountOfPoker(int[] digits, String[] colors, boolean[] used, int depth, int lastCardIndex) {
        count = Math.max(count, depth);
        if (depth == digits.length) {
            return;
        }

        for (int i = 0; i < digits.length; i++) {
            // 如果当前牌没有被使用过
            if (!used[i]) {
                // 使用当前牌
                // 如果上一张牌和当前牌的数字或者颜色相同，表示可以继续再打一张牌
                if (lastCardIndex == -1 || digits[lastCardIndex] == digits[i] || colors[lastCardIndex].equals(colors[i])) {
                    used[i] = true;
                    getCountOfPoker(digits, colors, used, depth + 1, i);
//                    count = Math.max(count, );
                    used[i] = false;
                }

            }
        }
        
    }
}